﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RFIDStockManagement.Common.Public.InterFace;
using DevExpress.XtraEditors;
using RFIDStockManagement.BLL;

namespace RFIDStockManagement.Client
{
    public partial class LoginForm : XtraForm, ISwitchMainForm
    {

        private bool isRealColse;
        private RUser _curUser;


        public RUser LogUser
        {
            get
            {
                return _curUser;
            }
        }

        public LoginForm()
        {
            InitializeComponent();
            isRealColse = true;
            _curUser = new RUser();
        }


        #region ISwitchMainForm 成员

        public bool IsRealCloseForm
        {
            get
            {
                return isRealColse;
            }
            set
            {
                isRealColse = value;
            }
        }

        public void RealCloseForm()
        {
            isRealColse = true;
            this.Close();
        }

        public void SwitchCloseForm()
        {
            isRealColse = false;
            this.Close();
        }

        #endregion

        private void bntLogin_Click(object sender, EventArgs e)
        {
            string logName = txtLogName.Text.Trim();
            string pwdStr = txtPwd.Text.Trim();
            if (logName.Length <= 0 || pwdStr.Length <=0)
            {
                AlertForm.ShowMessage("请完整输入登录信息", "错误");
                return;
            }

            if (_curUser.Login(logName, pwdStr, false))
            {
                if (_curUser.IsAdmin)
                {
                    SwitchCloseForm();
                }
                else
                {
                    AlertForm.ShowMessage("您未具备系统管理员权限,不能登录此功能.", "登录错误");
                }
            }
            else
            {
                AlertForm.ShowMessage("您输入的用户名或密码错误,请重试", "登录错误");
            }


        }

        private void bntCancel_Click(object sender, EventArgs e)
        {
           
            RealCloseForm();
        }

    }
}
